#include <iostream>
#include <unordered_map>
using namespace std;
struct Node{
	int value;
	Node* next;
	Node(int _val):value(_val),next(nullptr){}
};
void showList(Node*);
Node* removeDuplicates(Node*);
Node* createList(int[],int);
int main(){
	int n[5]={1,1,2,3,3};
	Node* l=createList(n,5);
	l=removeDuplicates(l);
	showList(l);
	return 0;
}
void showList(Node* head){
	Node* p=head;
	while(p){
		cout<<p->value<<' ';
		p=p->next;
	}
}
Node* removeDuplicates(Node* head) {
    if (!head) return nullptr;
    unordered_map<int, int> map;
    Node* curr = head;
    while (curr) {
        map[curr->value]++;
        curr = curr->next;
    }
    Node* dummy = new Node(0);
    Node* p = dummy;
    curr = head;
    Node* next = nullptr;
    while (curr) {
        if (map[curr->value] == 1) {
            p->next = new Node(curr->value);
            p = p->next;
        }
        curr = curr->next;
    }
    Node* result = dummy->next;
    delete dummy;
    return result;
}
Node* createList(int values[],int size){
	Node* p=new Node(values[0]);
	Node* head=p;
	for(int i=1;i<size;++i){
		p->next=new Node(values[i]);
		p=p->next;
	}
	return head;
}
